package com.rzn.reading.controller;


import com.rzn.reading.JsonResult;
import com.rzn.reading.model.dto.rank.CreateRankInputDTO;
import com.rzn.reading.service.RankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 评级表 前端控制器
 * </p>
 *
 * @author rzn
 * @since 2022-02-12
 */
@RestController
@RequestMapping("//rank")
@Api(tags = "等级")
public class RankController {

    @Autowired
    private RankService rankService;

    @PostMapping("/insert")
    @ApiOperation("添加评级")
    public JsonResult insertRank(@RequestBody CreateRankInputDTO createRankInputDTO){
        Boolean res = rankService.insertRank(createRankInputDTO);
        if (res){
            return JsonResult.success();
        }else {
            return JsonResult.error();
        }
    }

    @GetMapping("/getRankInfo/{literatureId}")
    @ApiOperation("查询某个文献的评分")
    public JsonResult selectRank(@PathVariable Integer literatureId){
        Double res = rankService.getAvgRank(literatureId);
        return JsonResult.success(res);
    }

}

